package com.fivefu.core.camera.services.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fivefu.base.common.utils.str.StrUtils;
import com.fivefu.core.camera.entity.*;
import com.fivefu.core.camera.mapper.DbMonitorRegionMapper;
import com.fivefu.core.camera.services.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fivefu.core.camera.vo.response.ProPageList;
import com.fivefu.core.data.constant.PlatformEnum;
import com.fivefu.core.data.entity.DbFfskyeyeChannel;
import com.fivefu.core.data.entity.DbFfskyeyeDevice;
import com.fivefu.core.data.properties.StreamServiceMapProperties;
import com.fivefu.core.data.properties.StreamServiceProperties;
import com.fivefu.core.data.services.DbFfskyeyeChannelService;
import com.fivefu.core.data.services.DbFfskyeyeDeviceService;
import com.fivefu.core.hik.services.VideoService;
import com.fivefu.core.skyeye.event.services.MimirEventService;
import com.fivefu.core.skyeye.event.vo.StreamSlicesDataBean;
import com.fivefu.module.dictionary.entity.DbSysDict;
import com.fivefu.module.dictionary.service.DbSysDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 自定义探头组织 服务实现类
 * </p>
 *
 * @author 
 * @since 2022-09-27 15:14:41
 */
@Service
public class DbMonitorRegionServiceImpl extends ServiceImpl<DbMonitorRegionMapper, DbMonitorRegion> implements DbMonitorRegionService {

    @Autowired
    private MonitorCameraService monitorCameraService;

    @Autowired
    private DbMonitorRegionCameraService dbMonitorRegionCameraService;

    @Autowired
    private DbMonitorCameraService dbMonitorCameraService;

    @Autowired
    private DbSysDictService dbSysDictService;

    @Autowired
    private DbFfskyeyeChannelService dbFfskyeyeChannelService;

    @Autowired
    private DbFfskyeyeDeviceService dbFfskyeyeDeviceService;

    @Autowired
    private RegionService regionService;

    @Autowired
    private DbMonitorCameraLabelService dbMonitorCameraLabelService;

    @Autowired
    private DbMonitorLabelService dbMonitorLabelService;

    @Autowired
    private MimirEventService mimirEventService;

    @Autowired
    private VideoService videoService;

    @Autowired
    private CameraVideoService cameraVideoService;
    @Autowired
    private StreamServiceMapProperties streamServiceMapProperties;

    /**
     * 根据组织名称和层级查询相关信息
     * @param regionName   组织名称
     * @param pid          父级组织编号
     * @param id           组织编号
     * @return
     */
    @Override
    public DbMonitorRegion queryMonitorRegionByRegionName(String regionName,Long pid,Long id) {
        QueryWrapper<DbMonitorRegion> wrapper = new QueryWrapper<>();
        wrapper.eq("is_delete",0);
        if (StrUtils.isNotNull(regionName)) {
            wrapper.eq("region_name",regionName);
        }
        if (null != pid) {
            wrapper.eq("parent_region_id",pid);
        }
        if (null != id) {
            wrapper.eq("id",id);
        }
        DbMonitorRegion monitorRegion = baseMapper.selectOne(wrapper);
        return monitorRegion;
    }

    /**
     * 编辑文件夹
     * @param regionName 组织名称
     * @param parentRegionId 父级组织编号
     * @param id 组织编号
     * @param userid 操作用户编号
     */
    @Override
    public Long editMonitorRegion(String regionName, Long parentRegionId, Long id, String userid) {
        LocalDateTime time = LocalDateTime.now();

        DbMonitorRegion monitorRegion = new DbMonitorRegion();
        monitorRegion.setUpdatedBy(userid);
        monitorRegion.setUpdatedTime(time);
        monitorRegion.setRegionName(regionName);
        monitorRegion.setParentRegionId(parentRegionId);
        if (id != null){
            monitorRegion.setId(id);
            baseMapper.updateById(monitorRegion);
        }else{
            //查询层级
            if (parentRegionId.equals(0L)){
                monitorRegion.setLevel(1);
            }else{
                DbMonitorRegion parentRegion = queryMonitorRegionByRegionName(null,null,parentRegionId);
                if (parentRegion != null){
                    monitorRegion.setLevel(parentRegion.getLevel() + 1 );
                }
            }

            monitorRegion.setCreatedBy(userid);
            monitorRegion.setCreatedTime(time);
            monitorRegion.setEnable(1);
            monitorRegion.setIsDelete(0);
            baseMapper.insert(monitorRegion);
        }
        return monitorRegion.getId();
    }

    /**
     * 文件夹下添加相关探头信息
     * @param id 文件id
     * @param cameraCodes 探头id（多个探头id用逗号隔开）
     * @param userid 操作用户编号
     */
    @Override
    public void addMonitorRegionCameras(Long id, String cameraCodes, String userid) {
        //判断探头id是否为空
        if (StrUtils.isNull(cameraCodes)) {
            return;
        }

        //根据”,“将探头id切割
        String[] cameras = cameraCodes.split(",");
        List<String> cameraList = Arrays.asList(cameras);

        //编辑组织探头关联关系
        dbMonitorRegionCameraService.addMonitorRegionCameras(id,cameraList,userid);
    }

    /**
     * 查询自定义探头组织表中所有数据集
     * @return
     */
    @Override
    public List<DbMonitorRegion> queryMonitorRegionAllList() {
        QueryWrapper<DbMonitorRegion> wrapper = new QueryWrapper<>();
        wrapper.eq("is_delete",0);
        wrapper.orderByAsc("sort");
        List<DbMonitorRegion> resultList = baseMapper.selectList(wrapper);
        return resultList;
    }

    /**
     * 移除文件夹下探头
     * @param regionId       组织编号
     * @param cameraCode     探头id
     * @param userid         用户编号
     */
    @Override
    public void removeMonitorRegionCamera(Long regionId,String cameraCode, String userid) {
        dbMonitorRegionCameraService.removeMonitorRegionCamera(regionId,cameraCode,userid);
    }

    /**
     * 删除文件夹
     * @param regionId     组织编号
     * @param userid       用户编号
     */
    @Override
    public void deleteMonitorRegion(Long regionId, String userid) {
        List<DbMonitorRegion> regionList = new ArrayList<>();
        DbMonitorRegion monitorRegion = queryMonitorRegionByRegionName(null, null, regionId);
        //判断此文件夹是否有下级文件夹或探头
        //先获取所有探头组织数据集
        List<DbMonitorRegion> monitorRegions = queryMonitorRegionAllList();
        //根据父级组织编号分组
        Map<Long, List<DbMonitorRegion>> parentMap = monitorRegions.stream().collect(Collectors.groupingBy(k -> k.getParentRegionId(), Collectors.toList()));
        //获取组织探头关联表所有数据集
        List<DbMonitorRegionCamera> regionCameras = dbMonitorRegionCameraService.queryRegionCameras();
        //将查询结果根据组织id分组
        Map<Long,List<DbMonitorRegionCamera>> regionCameraMap = regionCameras.stream().collect(Collectors.groupingBy(k -> k.getRegionId(),Collectors.toList()));
        regionList = cycleMonitorRegion(monitorRegion,parentMap);
        regionList.add(monitorRegion);

        List<DbMonitorRegionCamera> regionCameraList = new ArrayList<>();
        for (DbMonitorRegion region : regionList) {
            if (regionCameraMap.containsKey(region.getId())) {
                List<DbMonitorRegionCamera> cameraList = regionCameraMap.get(region.getId());
                regionCameraList.addAll(cameraList);
            }
        }

        //删除组织探头关联关系
        dbMonitorRegionCameraService.deleteRegionCamera(regionCameraList,userid);
        //删除文件夹
        LocalDateTime time = LocalDateTime.now();
        regionList.forEach(region -> {
            region.setUpdatedBy(userid);
            region.setIsDelete(1);
            region.setUpdatedTime(time);
        });
        updateBatchById(regionList);
    }

    /**
     * 根据父级组织编号获取下级探头组织集合
     * @param monitorRegion
     * @param parentMap
     * @return
     */
    private List<DbMonitorRegion> cycleMonitorRegion(DbMonitorRegion monitorRegion, Map<Long, List<DbMonitorRegion>> parentMap) {
        List<DbMonitorRegion> resultList = new ArrayList<>();
        if (parentMap.containsKey(monitorRegion.getId())) {
            List<DbMonitorRegion> monitorRegions = parentMap.get(monitorRegion.getId());
            if (null != monitorRegions && monitorRegions.size() > 0) {
                resultList.addAll(monitorRegions);
                for (DbMonitorRegion region : monitorRegions) {
                    List<DbMonitorRegion> regionList = cycleMonitorRegion(region, parentMap);
                    if (null != regionList && regionList.size() > 0) {
                        resultList.addAll(regionList);
                    }
                }
            }
        }
        return resultList;
    }

    /**
     * 新增文件夹下探头列表查询
     * @param cameraName           探头名称(模糊)
     * @param cameraCode           探头编号(模糊)
     * @param cameraAreaid         所属区域
     * @param cameraStreetid 所属街道
     * @param cameraManufacturer   厂商
     * @param cameraStatus         探头状态
     * @param page                 当前页
     * @param limit                每页显示条数
     * @param id                   探头组织编号
     * @return
     */
    @Override
    public Page<ProPageList> queryCameraList(String cameraName, String cameraCode, String cameraAreaid, String cameraStreetid, String cameraManufacturer, String cameraStatus, String onlineStatus, Integer page, Integer limit, Long id) {
        Page<ProPageList> resultPage = new Page<>();
        //根据探头组织编号查询探头组织关联表
        List<DbMonitorRegionCamera> monitorRegionCameras = dbMonitorRegionCameraService.getRegionCameraList(id);
        List<String> excludeCodeList = new ArrayList<>();
        if (null != monitorRegionCameras && monitorRegionCameras.size() > 0) {
            excludeCodeList = monitorRegionCameras.stream().map(k -> k.getCameraCode()).collect(Collectors.toList());
        }
        Page<DbMonitorCamera> cameraPage = dbMonitorCameraService.queryCameraList(cameraName, cameraCode, null, cameraAreaid, cameraStreetid, cameraStatus,onlineStatus, cameraManufacturer, null, excludeCodeList, page, limit);
        List<DbMonitorCamera> cameraList = cameraPage.getRecords();

        //将探头信息转换
        List<ProPageList> proPageLists = monitorCameraService.cameraListToPageList(cameraList);
        resultPage.setRecords(proPageLists);
        resultPage.setTotal(cameraPage.getTotal());
        return resultPage;
    }

    /**
     * 查看探头源数据详情信息
     * @param id    探头id
     * @param code  探头唯一编码
     * @return
     */
    @Override
    public Map<String, Object> getOriginalDetails(String id,String code) {
        Map<String,Object> resultMap = new HashMap<>();
        String channelCode = "";
        if (StrUtils.isNotNull(id)) {
            //根据db_monitor_camera表中主键id获取源数据探头编号
            DbMonitorCamera camera = dbMonitorCameraService.getById(Long.valueOf(id));
            channelCode = camera.getCameraCode();//探头编号 -> 通道唯一标识
        } else if (StrUtils.isNotNull(code)){
            channelCode = code;
        }
        //根据通道唯一标识查询相关数据信息
        DbFfskyeyeChannel channel = dbFfskyeyeChannelService.queryByChannelCode(channelCode);
        //根据设备编号查询相关设备数据信息
        DbFfskyeyeDevice device = dbFfskyeyeDeviceService.queryDeviceByID(channel.getDeviceId());
        //设备型号
        if (StrUtils.isNotNull(device.getDeviceModel())) {
            resultMap.put("deviceModel",device.getDeviceModel());
        } else {
            resultMap.put("deviceModel","");
        }
        //通道类型
        if (StrUtils.isNotNull(channel.getChannelType())) {
            DbSysDict dict = dbSysDictService.queryDictDetail(null,channel.getChannelType());
            if (null != dict ) {
                resultMap.put("channelType",dict.getDictName());
            } else {
                resultMap.put("channelType","");
            }
        } else {
            resultMap.put("channelType","");
        }
        //设备名称
        if (StrUtils.isNotNull(device.getDeviceName())) {
            resultMap.put("deviceName",device.getDeviceName());
        } else {
            resultMap.put("deviceName","");
        }
        //通道名称
        if (StrUtils.isNotNull(channel.getChannelName())) {
            resultMap.put("channelName",channel.getChannelName());
        } else {
            resultMap.put("channelName","");
        }
        //设备序列号
        if (StrUtils.isNotNull(device.getDeviceSerialNum())) {
            resultMap.put("deviceSerialNum",device.getDeviceSerialNum());
        } else {
            resultMap.put("deviceSerialNum","");
        }
        //编码通道能力
        String functions = "";
        if (StrUtils.isNotNull(channel.getCameraFuncitons())) {
            String[] ability = channel.getCameraFuncitons().split(",");
            for (String s : ability) {
                DbSysDict dict = dbSysDictService.queryDictDetail(null,s);
                if (null != dict ) {
                    String m = dict.getDictName() + "-";
                    functions += m;
                }
            }
            if (StrUtils.isNotNull(functions)) {
                resultMap.put("functions",functions.substring(0,functions.length() - 1));
            } else {
                resultMap.put("functions",functions);
            }
        } else {
            resultMap.put("functions",functions);
        }
        //ip地址
        if (StrUtils.isNotNull(device.getDeviceIp())) {
            resultMap.put("ip",device.getDeviceIp());
        } else {
            resultMap.put("ip","");
        }
        //厂商
        if (StrUtils.isNotNull(device.getDeviceManufacturer())) {
            DbSysDict dict = dbSysDictService.queryDictDetail(null,device.getDeviceManufacturer());
            if (null != dict ) {
                resultMap.put("manufacturer",dict.getDictName());
            } else {
                resultMap.put("manufacturer","");
            }
        } else {
            resultMap.put("manufacturer","");
        }
        //备注
        if (StrUtils.isNotNull(device.getDeviceRemark())) {
            resultMap.put("remark",device.getDeviceRemark());
        } else {
            resultMap.put("remark","");
        }
        return resultMap;
    }

    /**
     * 查看探头基础数据详情信息
     * @param id   探头id
     * @return
     */
    @Override
    public Map<String, Object> getBasisDetails(Long id) {
        Map<String,Object> resultMap = new HashMap<>();
        DbMonitorCamera camera = dbMonitorCameraService.getById(id);
        //探头编号
        resultMap.put("cameraCode",camera.getCameraCode());
        //探头类型
        if (StrUtils.isNotNull(camera.getCameraType())) {
            DbSysDict dict = dbSysDictService.queryDictDetail(null,camera.getCameraType());
            if (null != dict ) {
                resultMap.put("cameraType",dict.getDictName());
                resultMap.put("cameraTypeCode",dict.getDictCode());
            } else {
                resultMap.put("cameraType","");
                resultMap.put("cameraTypeCode","");
            }
        } else {
            resultMap.put("cameraType","");
            resultMap.put("cameraTypeCode","");
        }

        //所属城区
        //根据城区编号查询城区名称
        if (StrUtils.isNotNull(camera.getCameraAreaid())) {
            String areaName = regionService.queryAreaNameByCode(camera.getCameraAreaid());
            if (StrUtils.isNotNull(areaName)) {
                resultMap.put("areaName",areaName);
                resultMap.put("areaId",camera.getCameraAreaid());
            } else {
                resultMap.put("areaName","");
                resultMap.put("areaId","");
            }
        } else {
            resultMap.put("areaName","");
            resultMap.put("areaId","");
        }

        //纬度坐标
        if (StrUtils.isNotNull(camera.getCameraLatitude() + "")) {
            resultMap.put("cameraLatitude",camera.getCameraLatitude());
        } else {
            resultMap.put("cameraLatitude","");
        }
        //探头名称
        if (StrUtils.isNotNull(camera.getCameraName())) {
            resultMap.put("cameraName",camera.getCameraName());
        } else {
            resultMap.put("cameraName","");
        }
        //探头状态
        if ("0".equals(camera.getCameraStatus())) {
            resultMap.put("cameraStatus","离线");
            resultMap.put("cameraStatusId",camera.getCameraStatus());
        } else if ("1".equals(camera.getCameraStatus())) {
            resultMap.put("cameraStatus","在线");
            resultMap.put("cameraStatusId",camera.getCameraStatus());
        }
        //所属街道
        //通过城区和街道编号查询街道名称
        if (StrUtils.isNotNull(camera.getCameraStreetid()) && StrUtils.isNotNull(camera.getCameraAreaid())) {
            String streetName = regionService.queryStreetNameByCode(camera.getCameraAreaid(),camera.getCameraStreetid());
            if (StrUtils.isNotNull(streetName)) {
                resultMap.put("streetName",streetName);
                resultMap.put("streetId",camera.getCameraStreetid());
            } else {
                resultMap.put("streetName","");
                resultMap.put("streetId","");
            }
        } else {
            resultMap.put("streetName","");
            resultMap.put("streetId","");
        }
        //经度坐标
        if (StrUtils.isNotNull(camera.getCameraLongitude() + "")) {
            resultMap.put("cameraLongitude",camera.getCameraLongitude());
        } else {
            resultMap.put("cameraLongitude","");
        }
        //厂商
        if (StrUtils.isNotNull(camera.getCameraManufacturer())) {
            DbSysDict mdict = dbSysDictService.queryDictDetail(null,camera.getCameraManufacturer());
            if (null != mdict ) {
                resultMap.put("manufacturer",mdict.getDictName());
                resultMap.put("manufacturerCode",camera.getCameraManufacturer());
            } else {
                resultMap.put("manufacturer","");
                resultMap.put("manufacturerCode","");
            }
        } else {
            resultMap.put("manufacturer","");
            resultMap.put("manufacturerCode","");
        }
        //标签
        //通过探头编号查询关联标签信息
        String label = "";
        List<DbMonitorCameraLabel> cameraLabels = dbMonitorCameraLabelService.queryLabelsByCameraCode(camera.getCameraCode());
        if (null != cameraLabels && cameraLabels.size() > 0) {
            Set<Long> labelIds = cameraLabels.stream().map(k -> k.getLabelId()).collect(Collectors.toSet());
            for (Long labelId : labelIds) {
                DbMonitorLabel monitorLabel = dbMonitorLabelService.getById(labelId);
                if (null != monitorLabel) {
                    String name = monitorLabel.getLabelName() + ",";
                    label += name;
                }
            }
            if (StrUtils.isNotNull(label)) {
                resultMap.put("label",label.substring(0,label.length() - 1));
            } else {
                resultMap.put("label","");
            }
        } else {
            resultMap.put("label","");
        }
        //详细地址
        if (StrUtils.isNotNull(camera.getCameraAddress())) {
            resultMap.put("cameraAddress",camera.getCameraAddress());
        } else {
            resultMap.put("cameraAddress","");
        }
        return resultMap;
    }

    /**
     * 根据探头编号查询视频播放地址/场景图片
     * @param id            探头id
     * @param type          查询类型(1:视频播放地址，2:场景图片)
     * @param protocal      取流协议(共同协议：rtsp,rtmp,hls,海康额外有：hik,ws,大华额外有：FLV_HTTP)
     * @param subType       码流类型(0:主码流,1:辅流1,2:辅流2。默认为0主码流)只有大华有
     * @return
     */
    @Override
    public Map<String, Object> getCameraVideoUrl(Long id,Integer type,String protocal,String subType) throws Exception {
        Map<String, Object> resultMap = new HashMap<>();
        DbMonitorCamera camera = dbMonitorCameraService.getById(id);
        Integer st = null;
        if (StrUtils.isNotNull(subType)) {
            st = Integer.valueOf(subType);
        }
        String videoUrl = "";
        //视频播放地址
        String url = dbFfskyeyeChannelService.queryUrlByChannelCode(camera.getCameraCode(),protocal,st);
        if (StrUtils.isNotNull(url)) {
            JSONObject jsonUrl = JSONObject.parseObject(url);
            videoUrl = jsonUrl.getString("url");
        }
        resultMap.put("url",videoUrl);
        if (2 == type) {//查询场景图片
            if (StrUtils.isNotNull(videoUrl)) {
                Map<String, Object> screenshots = screenshots(id, videoUrl);
                resultMap.put("picture",screenshots.get("url").toString());
            } else {
                resultMap.put("picture","");
            }
        }
        return resultMap;
    }

    /**
     * 视频截图
     * @param id     探头编号
     * @param url    视频播放地址url
     * @return
     * @throws Exception
     */
    @Override
    public Map<String,Object> screenshots(Long id, String url) throws Exception {
        Map<String ,Object> resultMap = new HashMap<>();
        String videoUrl = "";
        //根据探头编号获取平台标识
        DbMonitorCamera camera = dbMonitorCameraService.getById(id);
        DbFfskyeyeChannel dbFfskyeyeChannel = dbFfskyeyeChannelService.queryByChannelCode(camera.getCameraCode());
        String platFormCode = dbFfskyeyeChannel.getPlatformChannelCode();//平台监控点唯一编码
        if (PlatformEnum.HIKVERSION.getPlatformCode().equals(dbFfskyeyeChannel.getPlatformCode())) {
            String data = videoService.getManualCapture(platFormCode);
            if (StrUtils.isNotNull(data)) {
                JSONObject jsonObject = JSONObject.parseObject(data);
                if (StrUtils.isNotNull(jsonObject.get("picUrl").toString())) {
                    videoUrl = jsonObject.get("picUrl").toString();
                }
            }
        } else if (PlatformEnum.HILLSTONE.getPlatformCode().equals(dbFfskyeyeChannel.getPlatformCode())) {
            Map<String, Object> videoMap = cameraVideoService.snapeCamera(platFormCode, url);
            if (null != videoMap) {
                videoUrl = videoMap.get("url").toString();
            }
        } else if (streamServiceMapProperties.getSnapeVideoService() != null
                && streamServiceMapProperties.getSnapeVideoService().containsKey(dbFfskyeyeChannel.getPlatformCode())
                && streamServiceMapProperties.getSnapeVideoService().get(dbFfskyeyeChannel.getPlatformCode()).getEnable() ){
            StreamServiceProperties streamService = streamServiceMapProperties.getSnapeVideoService().get(dbFfskyeyeChannel.getPlatformCode());
            Map<String, String> paramMap = new HashMap<>();
            paramMap.put("id", id.toString());
            paramMap.put("url", url);
            videoUrl =  streamServiceMapProperties.queryStreamService(streamService, paramMap);
        } else {
            Map<String, Object> videoMap = cameraVideoService.snapeCamera(platFormCode, url);
            if (null != videoMap) {
                videoUrl = videoMap.get("url").toString();
            }
        }
        resultMap.put("url", videoUrl);
        return resultMap;
    }

    /**
     * 查看探头历史切片
     * @param id  探头id
     * @param stime 开始时间(yyyyMMddHHmmss)
     * @param etime 结束时间(yyyyMMddHHmmss)
     * @param pageNo 页码
     * @param pageSize 数量
     * @return
     */
    @Override
    public Map<String, Object> getBasisDetailPicture(Long id, String stime, String etime, Integer pageNo, Integer pageSize) {
        Map<String,Object> resultMap = new HashMap<>();
        DbMonitorCamera camera = dbMonitorCameraService.getById(id);
        //视频截图及照片
        List<StreamSlicesDataBean> streamSlicesData = mimirEventService.getStreamSlicesData(camera.getCameraCode(), stime, etime, pageNo, pageSize);
        if (null != streamSlicesData && streamSlicesData.size() > 0) {
            List<String> captureList = streamSlicesData.stream().map(k -> k.getImagePath()).collect(Collectors.toList());
            resultMap.put("videoCapture",captureList.get(0));
            for (StreamSlicesDataBean bean : streamSlicesData) {
                //调整图片时间格式
                SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
                try {
                    Date time = df.parse(bean.getCreatedTime());
                    String starTime = LocalDateTime.ofInstant(time.toInstant(), ZoneId.systemDefault()).toString();
                    bean.setCreatedTime(starTime.replace("T"," "));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
            resultMap.put("picture",streamSlicesData);
        } else {
            resultMap.put("videoCapture","");
            resultMap.put("picture","");
        }
        return resultMap;
    }

    /**
     * 获取视频回放URL
     * @param id        探头id
     * @param stime     回放开始时间(yyyy-MM-dd HH:mm:ss)
     * @param etime     回放结束时间(yyyy-MM-dd HH:mm:ss)
     * @param scheme    协议类型，共有：rtsp、rtmp、hls三种,海康额外：hik,ws(海康默认hik,大华默认rtsp)
     * @return
     */
    @Override
    public Map<String,Object> queryPlaybackURL(Long id, String stime, String etime, String scheme) {
        Map<String, Object> resultMap = new HashMap<>();
        DbMonitorCamera camera = dbMonitorCameraService.getById(id);
        String playbackUrl = "";
        //视频播放地址
        String url = dbFfskyeyeChannelService.queryPlaybackURI(camera.getCameraCode(),stime,etime,scheme);
        if (StrUtils.isNotNull(url)) {
            JSONObject jsonUrl = JSONObject.parseObject(url);
            playbackUrl = jsonUrl.getString("url");
        }
        resultMap.put("url",playbackUrl);
        return resultMap;
    }
}
